/**
 * @author wonderful-WuDaoHong
 * @create 20140530
 * @description ����jquery�������ʾ��
 */


(function(){
	var timeOutRmv;
$.wdfProgress={
		progress:function(info,contentObj,isShowCloseBtn,isShowOkBtn){
			contentObj.find("div[id*='_wdfProgress']").remove();
			var progDiv=$("<div id='"+contentObj.attr("id")+"_wdfProgress_Prog' class='wdfProgress_Prog'><div/>");
			var msg=$("<div class='wdfProgress_loadingImg'>"+info+"</div>");
			var bgDiv=$("<div id='"+contentObj.attr("id")+"_wdfProgress_Bg' class='wdfProgress_Bg'><div/>");
			progDiv.append(msg);
			contentObj.append(progDiv);
			contentObj.append(bgDiv);
			contentObj.css("overflow","hidden");
			var progress=progDiv;
            if(isShowOkBtn&&typeof(isShowOkBtn)=="function"){
                var okBtn=$("<div class='okBtn' title='确定'>确定</div>");
                okBtn.bind("click",function(){
                    if(!$(this).data("isDisabled")){
                        $(this).data("isDisabled",true);
                    }else{
                        return;
                    }
                    isShowOkBtn();
                });
                progress.append(okBtn);
            }
			if(isShowCloseBtn&&isShowOkBtn){
                msg.attr("style","");
				if(progress.find(".closeBtn").length>0)
					return;
				var closeBtn=$("<div class='closeBtn' title='取消'>取消</div>");
				closeBtn.bind("click",function(){
					contentObj.find(".wdfProgress_Prog").remove();
					contentObj.find(".wdfProgress_Bg").remove();
					contentObj.css("overflow","");
					if(typeof(isShowCloseBtn)=="function"){
                        isShowCloseBtn();
					}
				});
				progress.append(closeBtn);
			}else{
                msg.css("height","8px");
                msg.css("padding-top","0");
                msg.css("margin-top","-10px");
			}


			
			function fixedPosition(){
				var left=contentObj.scrollLeft();
				var top=contentObj.scrollTop();
				
				if(contentObj.is("body")){
					left=$(document).scrollLeft();
					top=$(document).scrollTop();
					if(top==0){
						$(document).scrollTop(0);
					}
					if(left==0){
						$(document).scrollLeft(0);
					}
				}
				bgDiv.css({
					left:left,
					top:top
				});
				var progLeft=bgDiv.width()/2+left;				
				var progTop=bgDiv.height()/3+top;
				progDiv.css({
					left:"50%",
					top:progTop,
					marginLeft:"-170px"
				});
				return fixedPosition;
			}
			if(contentObj.data("fixedPosition"))
			$(window).unbind("resize",contentObj.data("fixedPosition"));
			contentObj.data("fixedPosition",fixedPosition());
			$(window).bind("resize",contentObj.data("fixedPosition"));
		},
		//�����Ϣ�����¼���λ posObj��λ��Ԫ��$Ԫ�ض���,contentObj��ȿؼ�������$Ԫ�ض���
		dynamicPos:function(posObj,contentObj){
			/*posObj.unbind("scroll",posObj.data("wdfProg_FixedPosition"));
			posObj.data("wdfProg_FixedPosition",posObj.bind("scroll",contentObj.data("fixedPosition")));*/
		},
		//�Ƴ�����
		progRemove:function(contentObj,callback,time){
            timeOutRmv = setTimeout(function(){
				contentObj.find(".wdfProgress_Prog").remove();
				contentObj.find(".wdfProgress_Bg").remove();
				contentObj.css("overflow","");
				contentObj.unbind("wdfProg_FixedPosition",contentObj.data("wdfProg_FixedPosition"));
				if(callback)
				callback();
			},time?time:500);
		},
		showMsg:function(info,contentObj,isShowCloseBtn,closeCallBack,closeTime){
			var infoContent=contentObj.find(".wdfProgress_loadingImg").text(info);
			contentObj.find(".wdfProgress_loadingImg").addClass("hidLoadingImg");
			var progress=contentObj.find(".wdfProgress_Prog");
			clearTimeout(timeOutRmv);
            $.wdfProgress.progRemove(contentObj,null,closeTime?closeTime:1000);
//			if(isShowCloseBtn){
//				if(progress.find(".closeBtn").length>0)
//					return;
//				var closeBtn=$("<div class='closeBtn' title='�ر�'>ȡ��</div>");
//				closeBtn.bind("click",function(){
//					contentObj.find(".wdfProgress_Prog").remove();
//					contentObj.find(".wdfProgress_Bg").remove();
//					contentObj.css("overflow","");
//					if(closeCallBack){
//						closeCallBack(closeBtn);
//					}
//				});
//				progress.append(closeBtn);
//			}
		}
};
})();
$(function () {
    $("input[type=text]").keyup(function(e){
        var theEvent = window.event || e;
        if(theEvent.keyCode ==13){
            $(this).parents("form").find(".search_btn").click();
            $(this).parents("form").find(".okBtn").click();
        }
    });
    $("select").change(function () {
        $(this).parents("form").find(".search_btn").click();
    })
});